package com.shitu.soulemo.d;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.shitu.base.BaseFragment;
import com.shitu.soulemo.R;
import com.shitu.soulemo.rn.RNIdSwitchActivity;
import com.shitu.soulemo.rn.RNSettingActivity;
import com.shitu.soulemo.utils.AccountHelper;

/**
 * Created by majie on 2018/3/18.
 */

public class DFragment extends BaseFragment {
    private RelativeLayout setting;
    private RelativeLayout idSwitch;
    private TextView name;
    private ImageView avatar;
    private TextView type;
    private TextView address;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.mine_fragment, null);
        setting = view.findViewById(R.id.setting);
        idSwitch = view.findViewById(R.id.idswitch);

        name = view.findViewById(R.id.name);
        avatar = view.findViewById(R.id.avatar);
        type = view.findViewById(R.id.type);
        address = view.findViewById(R.id.address);

        initViews();
        return view;
    }

    private void initViews() {
        if (!TextUtils.isEmpty(AccountHelper.getUser().trueName)) {
            name.setText(AccountHelper.getUser().trueName);
        }
        if (AccountHelper.isRequire()) {
            type.setText("需求方");
        } else {
            type.setText("供给方");
        }
        if (getActivity() != null) {
            Glide.with(getActivity()).load(AccountHelper.getUser().avatar).into(avatar);
        }
        setting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RNSettingActivity.start(getActivity());
            }
        });

        idSwitch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RNIdSwitchActivity.start(getActivity());
            }
        });
    }
}
